//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <ddk.h>

//
// Device Drivers
//

#define DEVICENAME_COMPOUNDCHANNEL             L"compoundchannel"
EXTERN IDeviceDriver * CDECL CreateCCompoundChannelObject(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_COMPOUNDCHANNELMANAGER      L"compoundchannelmanager"
EXTERN IDeviceDriver * CDECL CreateCompoundChannelManager(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_DBGSTUBMANAGER          L"dbgstubmanager"
EXTERN IDeviceDriver * CDECL CreateDbgStubManager(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_REGEVENTMAN      L"RegEventMan"
EXTERN IDeviceDriver * CDECL RegisterEventManager(
                uint_t uDeviceNo, void *pvParameter);

// KTFS
#define DEVICENAME_KTFS            L"ktfsdriver"

EXTERN IDeviceDriver * CDECL CreateKtfs(uint_t uDeviceNo, void *pvParameter);

// DMA Controller
#define DEVICENAME_DMACONTROLLER        L"dmacontroller"

EXTERN IDeviceDriver * CDECL CreateDmaController(
                uint_t uDeviceNo, void *pvParameter);

// RAM Disk
#define DEVICENAME_RAMDISK              L"ramdisk"

EXTERN IDeviceDriver * CDECL CreateRamDisk(
                uint_t uDeviceNo, void *pvParameter);

// IDE Controller
#define DEVICENAME_IDECONTROLLER        L"idecontroller"

EXTERN IDeviceDriver * CDECL CreateIDEController(
                uint_t uDeviceNo, void *pvParameter);

// IDE Drive
#define DEVICENAME_IDEDRIVE             L"idedrive"

EXTERN IDeviceDriver * CDECL CreateIDEDrive(uint_t uDeviceNo, void *pvParameter);

// IDE Partition
#define DEVICENAME_IDEPARTITION         L"idepartition"

EXTERN IDeviceDriver * CDECL CreateIDEPartition(uint_t uDeviceNo, void *pvParameter);

// Serial
#define DEVICENAME_SERIAL               L"serial"

EXTERN IDeviceDriver * CDECL CreateSerial(uint_t uDeviceNo, void *pvParameter);

// Mouse
#define DEVICENAME_MOUSE                L"mouse"

EXTERN IDeviceDriver * CDECL CreateMouse(uint_t uDeviceNo, void *pvParameter);

//Keyboard
#define DEVICENAME_KEYBOARD             L"keyboard"

EXTERN IDeviceDriver * CDECL CreatePS2Keyboard(uint_t uDeviceNo, void *pvParameter);

// Console
#define DEVICENAME_CONSOLE              L"console"

EXTERN IDeviceDriver * CDECL CreateConsole(uint_t uDeviceNo, void *pvParameter);

// RTL Drive
#define DEVICENAME_RTL8139              L"rtl8139"

EXTERN IDeviceDriver * CDECL CreateRtl8139(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_RTL4USNET            L"eth"//L"rtl4usnet"

EXTERN IDeviceDriver * CDECL CreateRtl4Usnet(uint_t uDeviceNo, void *pvParameter);

// Boot file list driver
#define DEVICENAME_BOOTMODS             L"bootmods"

EXTERN IDeviceDriver * CDECL CreateBootModules(uint_t uDeviceNo, void *pv);

// statserver
#define DEVICENAME_STATDDRIVER          L"mstatserver"
EXTERN IDeviceDriver * CDECL CreateMStatServer(uint_t uDeviceNo, void *pvParameter);

// pppdrv
#define DEVICENAME_PPPDRV               L"pppdrv"
EXTERN IDeviceDriver * CDECL CreatePppdrv(uint_t uDeviceNo, void *pvParameter);

#if (_TEST_TYPE == 2) /* Test for Daily Build */
#define DEVICENAME_TESTINGDRIVER        L"testingserver"
EXTERN IDeviceDriver * CDECL CreateTestingServer(
                uint_t uDeviceNo, void *pvParameter);
#endif //_TEST_TYPE == 2

#if (_TEST_TYPE == 7) /* Test for Marshalling */
#define DEVICENAME_TESTINGDRIVER        L"testingserver"
EXTERN IDeviceDriver * CDECL CreateTestingServer(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_MARSHALTEST          L"marshaltest1"
EXTERN IDeviceDriver * CDECL CreateMarshalTest(uint_t uDeviceNo, void *pvParameter);
#endif //_TEST_TYPE == 7

#ifdef _DOC_SAMPLES

// MyBuff
#define DEVICENAME_MYBUFF               L"MyBuff"

EXTERN IDeviceDriver* CDECL CreateMyBuff(uint_t uDeviceNo, void *pvParameter);

#endif // _DOC_SAMPLES

#if (_TEST_TYPE == 1) /* Test for DDK */

// ddktstmemory
#define DEVICENAME_DDKTSTMEMORY         L"ddktstmemory"
EXTERN IDeviceDriver * CDECL CreateDDKTstMemory(uint_t uDeviceNo, void *pvParameter);

// ddktsttimer
#define DEVICENAME_DDKTSTTIMER          L"ddktsttimer"
EXTERN IDeviceDriver * CDECL CreateDDKTstTimer(uint_t uDeviceNo, void *pvParameter);

// ddktstthread
#define DEVICENAME_DDKTSTTHREAD         L"ddktstthread"
EXTERN IDeviceDriver * CDECL CreateDDKTstThread(uint_t uDeviceNo, void *pvParameter);

#endif //_TEST_TYPE == 1

#if (_TEST_TYPE == 100) /* Test for DDK */

#define DEVICENAME_VIRTUAL_MILLISECONDSTICKS0       L"MillisecondsTicks0"
EXTERN IDeviceDriver * CDECL CreateMilliSecondsTicks(uint_t uDeviceNo,
                void *pvParameter);
// Floppy Driver
#define DEVICENAME_FLOPPYDRIVER         L"floppydriver"
EXTERN IDeviceDriver * CDECL CreateFloppyDriver(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_NULLDEVICENAME       L""

#define DEVICENAME_NULLNO               L"nullnodev"

#define DEVICENAME_LEN31    L"lengthofdevicename000000equal31"
//                            123456789012345678901234567890123
//#define DEVICENAME_LEN32    L"lengthofdevicename0000000equal32"

#define DEVICENAME_UPPERNAME            L"UPPNAME"

#define DEVICENAME_PRNPARAMETERS        L"printparameters"

EXTERN IDeviceDriver * CDECL CreatePrnParameters(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_REGDEVICE            L"regdevice"

EXTERN IDeviceDriver * CDECL CreateRegDevice(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_UNREGDEVICE          L"unregdevice"
#define DEVICENAME_UNREGDEV01           L"unregdev01"
//the unregdev02 device has no driver in driver config
#define DEVICENAME_UNREGDEV02           L"unregdev02"

EXTERN IDeviceDriver * CDECL CreateUnregDevice(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_SLEEP0                   L"SleepServer0"
EXTERN IDeviceDriver * CDECL CreateSleepServer0(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_MUTEX0                   L"MutexSever0"
EXTERN IDeviceDriver * CDECL CreateMutexServer0(
                uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_CONDITION0               L"ConditionSever0"
EXTERN IDeviceDriver * CDECL CreateConditionServer0(uint_t uDeviceNo,
                                                        void *pvParameter);

#define DEVICENAME_VIRTUAL_EVENT0                   L"EventServer0"
EXTERN IDeviceDriver * CDECL CreateEventServer0(uint_t uDeviceNo, void *pvParameter);

// Test Mem Drive
#define DEVICENAME_TESTMEM              L"testmem"
EXTERN IDeviceDriver * CDECL CreateTestmem(uint_t uDeviceNo, void *pvParameter);

// Test Interrupt
#define DEVICENAME_TINTERRUPT           L"tinterrupt"
EXTERN IDeviceDriver * CDECL CreateTInterrupt(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_READERWRITERLOCK0        L"ReaderWriterLockServer0"
EXTERN IDeviceDriver * CDECL CreateReaderWriterLockServer0(uint_t uDeviceNo,
                void *pvParameter);

#define DEVICENAME_VIRTUAL_DELAY0                   L"DelayServer0"
EXTERN IDeviceDriver * CDECL CreateDelayServer0(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_TIMER0                   L"TimerServer0"
EXTERN IDeviceDriver * CDECL CreateTimerServer0(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_PREEMPTION0              L"PreemptionServer0"
EXTERN IDeviceDriver * CDECL CreatePreemptionServer0(uint_t uDeviceNo,
                void *pvParameter);

#define DEVICENAME_VIRTUAL_YIELD0                   L"YieldServer0"
EXTERN IDeviceDriver * CDECL CreateYieldServer0(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_VIRTUAL_THREAD0                  L"ThreadServer0"
EXTERN IDeviceDriver * CDECL CreateThreadServer000(uint_t uDeviceNo,
                void *pvParameter);
//practical routines
#define DEVICENAME_PRACTICALROUTINES                L"routines"
EXTERN IDeviceDriver * CDECL CreateRoutines(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_INTERRUPTSERVICES                L"interruptsvr"
EXTERN IDeviceDriver * CDECL CreateInterruptSvr(uint_t uDeviceNo, void *pvParameter);

#endif //_TEST_TYPE == 100

#define DEVICENAME_GDIVGA                           L"display"

EXTERN IDeviceDriver * CDECL CreateGDIVGA(uint_t uDeviceNo, void *pvParameter);

// for slip protocal
#define DEVICENAME_SLIP                             L"slip"

EXTERN IDeviceDriver * CDECL CreateSLIP(uint_t uDeviceNo, void *pvParameter);

#define DEVICENAME_SERVICE                  L"systemserver"

EXTERN IDeviceDriver * CDECL CreateServices(uint_t uDeviceNo, void *pvParameter);

//
// Device Configurations
//
// NOTE: the device name can't be more than 31 words
STATIC DECL_DATAINIT DeviceConfig s_deviceConfigs[] = {
    // System devices
    { DEVICENAME_REGEVENTMAN,       DEVICENO_NONE, NULL },
    { DEVICENAME_DMACONTROLLER,     DEVICENO_NONE, NULL },

//    { DEVICENAME_RAMDISK,           0, NULL },
//    { DEVICENAME_RAMDISK,           1, NULL },
//    { DEVICENAME_RAMDISK,           2, NULL },

    { DEVICENAME_IDECONTROLLER,     0, NULL },
//    { DEVICENAME_IDECONTROLLER,     1, NULL },

    { DEVICENAME_SERIAL,            1, NULL},
    { DEVICENAME_SERIAL,            2, NULL},

    { DEVICENAME_KEYBOARD,          0, NULL},
    { DEVICENAME_CONSOLE,           0, NULL},

    { DEVICENAME_MOUSE,             DEVICENO_NONE, NULL},

    { DEVICENAME_BOOTMODS,          0, NULL },

    { DEVICENAME_RTL8139,           0, NULL },

    { DEVICENAME_RTL4USNET,         0, NULL },

    { DEVICENAME_STATDDRIVER,       DEVICENO_NONE, NULL },

#if (_TEST_TYPE == 2) /* Test for Daily Build */
    { DEVICENAME_TESTINGDRIVER,     DEVICENO_NONE, NULL },
#endif //_TEST_TYPE == 2

#if (_TEST_TYPE == 7) /* Test for Marshalling */
    { DEVICENAME_TESTINGDRIVER,     DEVICENO_NONE, NULL },
    { DEVICENAME_MARSHALTEST,       DEVICENO_NONE, NULL },
#endif //_TEST_TYPE == 7

    { DEVICENAME_GDIVGA,            0, NULL},

#ifdef _DOC_SAMPLES
    { DEVICENAME_MYBUFF,            0, NULL },
    { DEVICENAME_MYBUFF,            1, NULL },
#endif // _DOC_SAMPLES

#if (_TEST_TYPE == 1) /* Test for DDK */
    { DEVICENAME_DDKTSTMEMORY,      DEVICENO_NONE, NULL },
    { DEVICENAME_DDKTSTTIMER,       DEVICENO_NONE, NULL },
    { DEVICENAME_DDKTSTTHREAD,       DEVICENO_NONE, NULL },
#endif //_TEST_TYPE == 1

#if (_TEST_TYPE == 100) /* Test for DDK */
    { DEVICENAME_VIRTUAL_MILLISECONDSTICKS0,    DEVICENO_NONE, NULL },
    { DEVICENAME_FLOPPYDRIVER,      0, NULL },
    { DEVICENAME_VIRTUAL_SLEEP0,    DEVICENO_NONE, NULL },

    { DEVICENAME_NULLDEVICENAME,    0, NULL },
    { DEVICENAME_NULLNO,            DEVICENO_NONE, NULL },
    { DEVICENAME_NULLNO,            9, NULL },
    { DEVICENAME_LEN31,             0, NULL },
    { DEVICENAME_LEN31,             0x7FFFFFFF, NULL },
    { DEVICENAME_LEN31,             0x80000000, NULL },
    { DEVICENAME_LEN31,             0xFFFFFFFE, NULL },

    { DEVICENAME_UPPERNAME,         DEVICENO_NONE, NULL },

//    { DEVICENAME_LEN32,             DEVICENO_NONE, NULL },

    { DEVICENAME_PRNPARAMETERS,     0,  (void*)0x10000000},
    { DEVICENAME_PRNPARAMETERS,     0xFFFFFFFE, (void*)0x00000001 },
    { DEVICENAME_PRNPARAMETERS,     3, (void*)0xF3579135 },

    { DEVICENAME_REGDEVICE,         DEVICENO_NONE, NULL },
    { DEVICENAME_UNREGDEVICE,       DEVICENO_NONE, NULL },
    { DEVICENAME_UNREGDEV01,        DEVICENO_NONE, NULL },
    { DEVICENAME_UNREGDEV01,        0, NULL },
    { DEVICENAME_UNREGDEV02,        DEVICENO_NONE, NULL },

    { DEVICENAME_VIRTUAL_MUTEX0,    DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_CONDITION0,DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_EVENT0,    DEVICENO_NONE, NULL },
    { DEVICENAME_TESTMEM ,          0, NULL },
    { DEVICENAME_TINTERRUPT,            0, NULL },
    { DEVICENAME_VIRTUAL_READERWRITERLOCK0, DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_DELAY0,    DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_TIMER0,    DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_THREAD0,   DEVICENO_NONE, NULL },
    { DEVICENAME_PRACTICALROUTINES, DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_PREEMPTION0,   DEVICENO_NONE, NULL },
    { DEVICENAME_VIRTUAL_YIELD0,    DEVICENO_NONE, NULL },
    { DEVICENAME_INTERRUPTSERVICES, DEVICENO_NONE, NULL },
#endif //_TEST_TYPE == 100
    { DEVICENAME_SLIP,              DEVICENO_NONE, NULL },
    { DEVICENAME_PPPDRV,            DEVICENO_NONE, NULL },
    { DEVICENAME_KTFS,              DEVICENO_NONE, NULL },
    { DEVICENAME_COMPOUNDCHANNELMANAGER, DEVICENO_NONE, NULL },
    { DEVICENAME_SERVICE,           DEVICENO_NONE, NULL },
    { DEVICENAME_DBGSTUBMANAGER,    DEVICENO_NONE, NULL},
};

//
// Driver Configurations
//
STATIC DriverConfig s_driverConfigs[] = {
    // System device drivers
    { DEVICENAME_REGEVENTMAN,       &RegisterEventManager},
    { DEVICENAME_DMACONTROLLER,     &CreateDmaController },

    { DEVICENAME_RAMDISK,           &CreateRamDisk },

    { DEVICENAME_IDECONTROLLER,     &CreateIDEController },
    { DEVICENAME_IDEDRIVE,          &CreateIDEDrive },
    { DEVICENAME_IDEPARTITION,      &CreateIDEPartition },

    { DEVICENAME_SERIAL,            &CreateSerial },

    { DEVICENAME_KEYBOARD,           &CreatePS2Keyboard },

    { DEVICENAME_CONSOLE,           &CreateConsole },

    { DEVICENAME_MOUSE,             &CreateMouse },

    { DEVICENAME_BOOTMODS,          &CreateBootModules },

    { DEVICENAME_RTL8139,           &CreateRtl8139 },
    { DEVICENAME_RTL4USNET,         &CreateRtl4Usnet },

    { DEVICENAME_STATDDRIVER,       &CreateMStatServer },

#if (_TEST_TYPE == 2) /* Test for Daily Build */
    { DEVICENAME_TESTINGDRIVER,     &CreateTestingServer },
#endif //_TEST_TYPE == 2

#if (_TEST_TYPE == 7) /* Test for Marshalling */
    { DEVICENAME_TESTINGDRIVER,     &CreateTestingServer },
    { DEVICENAME_MARSHALTEST,       &CreateMarshalTest },
#endif //_TEST_TYPE == 7

    { DEVICENAME_GDIVGA,            &CreateGDIVGA },

#ifdef _DOC_SAMPLES
    { DEVICENAME_MYBUFF,            &CreateMyBuff },
#endif // _DOC_SAMPLES

#if (_TEST_TYPE == 1) /* Test for DDK */
    { DEVICENAME_DDKTSTMEMORY,      &CreateDDKTstMemory },
    { DEVICENAME_DDKTSTTIMER,       &CreateDDKTstTimer },
    { DEVICENAME_DDKTSTTHREAD,      &CreateDDKTstThread },
#endif //_TEST_TYPE == 1

#if (_TEST_TYPE == 100) /* Test for DDK */
    { DEVICENAME_VIRTUAL_MILLISECONDSTICKS0, &CreateMilliSecondsTicks },
    { DEVICENAME_FLOPPYDRIVER,      &CreateFloppyDriver },
    { DEVICENAME_NULLDEVICENAME,    &CreateRamDisk },
    { DEVICENAME_NULLNO,            &CreateRamDisk },
    { DEVICENAME_LEN31,             &CreateRamDisk },
    { DEVICENAME_UPPERNAME,         &CreateRamDisk },
    { DEVICENAME_PRNPARAMETERS,     &CreatePrnParameters },
    { DEVICENAME_REGDEVICE,         &CreateRegDevice },
    { DEVICENAME_UNREGDEVICE,       &CreateUnregDevice },
    { DEVICENAME_UNREGDEV01,        &CreateUnregDevice },
//    { DEVICENAME_LEN32,             &CreateRamDisk},
    { DEVICENAME_VIRTUAL_SLEEP0,    &CreateSleepServer0 },
    { DEVICENAME_VIRTUAL_MUTEX0,    &CreateMutexServer0 },
    { DEVICENAME_VIRTUAL_CONDITION0,&CreateConditionServer0},
    { DEVICENAME_VIRTUAL_EVENT0,    &CreateEventServer0 },
    { DEVICENAME_TESTMEM,           &CreateTestmem },
    { DEVICENAME_TINTERRUPT,         &CreateTInterrupt },
    { DEVICENAME_VIRTUAL_READERWRITERLOCK0, &CreateReaderWriterLockServer0 },
    { DEVICENAME_VIRTUAL_DELAY0,    &CreateDelayServer0 },
    { DEVICENAME_VIRTUAL_TIMER0,    &CreateTimerServer0 },
    { DEVICENAME_VIRTUAL_THREAD0,   &CreateThreadServer000 },
    { DEVICENAME_PRACTICALROUTINES, &CreateRoutines },
    { DEVICENAME_VIRTUAL_PREEMPTION0,   &CreatePreemptionServer0 },
    { DEVICENAME_VIRTUAL_YIELD0,    &CreatePreemptionServer0 },
    { DEVICENAME_INTERRUPTSERVICES, &CreateInterruptSvr },
#endif //_TEST_TYPE == 100
    { DEVICENAME_SLIP,              &CreateSLIP },
    { DEVICENAME_PPPDRV,            &CreatePppdrv },
    { DEVICENAME_KTFS,              &CreateKtfs },
    { DEVICENAME_COMPOUNDCHANNELMANAGER, &CreateCompoundChannelManager },
    { DEVICENAME_COMPOUNDCHANNEL, &CreateCCompoundChannelObject },
    { DEVICENAME_SERVICE,           &CreateServices},
    { DEVICENAME_DBGSTUBMANAGER,    &CreateDbgStubManager},
};

DzConfig dzcfg = {
    s_deviceConfigs,                // *pDeviceConfigs
    lengthof(s_deviceConfigs),      // uNumberOfDeviceConfigs

    s_driverConfigs,                // *pDriverConfigs
    lengthof(s_driverConfigs)       // uNumberOfDriverConfigs
};
